package com.bwie.controller;

import com.alibaba.fastjson.JSON;
import com.bwie.order.WeiXinUtil;
import com.bwie.pojo.PaymentOrder;
import com.bwie.service.PaymentOrderService;
import com.bwie.utils.R;
import com.bwie.vo.OrderVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author 上杉绘梨衣 && Sakura
 * @Yu 我们都是小怪兽，总有一天会被正义的奥特曼杀死。
 * @Yu "不知道从什么时候,我开始不喜欢社交，沉浸在自己的小圈子里"
 * @date 2025/9/12-20:05
 */
@RestController
@RequestMapping("/pay/index")
@Slf4j
public class PayController {
    @Autowired
    private PaymentOrderService paymentOrderService;


    @ApiOperation("支付")
    @PostMapping("/payOrder")
    public R payOrder(@RequestBody OrderVo orderVo) throws Exception {
        PaymentOrder paymentOrder = PaymentOrder.builder()
                .createTime(new Date())
                .errorCode("A")
                .orderNo(UUID.randomUUID().toString())
                .notifyUrl("url")
                .errorMsg("1")
                .expireTime(new Date())
                .payAmount(new BigDecimal(12))
                .payMethod("payMethod")
                .userIp("ip")
                .notifyStatus(1)
                .payTime(new Date())
                .build();

        boolean b = paymentOrderService.save(paymentOrder);

        String codeUrl = WeiXinUtil.payOrder(orderVo.getOrderId());

        return R.OK(codeUrl);
    }




    @PostMapping("/user")
    public Map<String, Object> createUser(@RequestBody Map<String, Object> user) {

        log.info("user:{}", JSON.toJSONString(user));

        log.info("user2:{}", JSON.toJSONString(user));

        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("message", "用户创建成功");
        map.put("data", user);
        map.put("timestamp",System.currentTimeMillis() );
        return map;

    }

    @PostMapping("/user2")
    public Map<String, Object> createUser(@RequestBody OrderVo orderVo) {

        log.info("user:{}", JSON.toJSONString(orderVo));

        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("message", "用户创建成功");
        map.put("data", orderVo);
        map.put("timestamp",System.currentTimeMillis() );
        return map;

    }

    @ApiOperation("/data")
    public Map<String, Object> receiveData(@RequestBody Map<String, Object> data) {

        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("message", "数据接收成功");
        map.put("receiveData", data);
        map.put("timestamp",System.currentTimeMillis() );
        return map;

    }



}
